/*
 * Created on Feb 23, 2004
 *
 * Author: Sandeep Prakash
 * Project: Sucxentv2 (using leaf nodes only)
 */
package dbsucxentW.storageW.loadersW.relationalW;

import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Connection;
import dbsucxentW.storageW.entitiesW.PathCollection;
import dbsucxentW.storageW.loadersW.Store;

/**
 * @author Administrator
 *
 * 
 */
public class PathCollectionRelational extends PathCollection {
    private Connection dbConnection;
    private String dataSourceName;
    
    public PathCollectionRelational(Store store, Connection dbConnection, String dataSourceName) {
        super(store);
        this.dbConnection = dbConnection;
        this.dataSourceName = dataSourceName;      
        loadPaths();
    }
 
    public void loadPaths() {
        try {
            Statement stmt = dbConnection.createStatement();
            ResultSet rs = stmt.executeQuery(
                    "SELECT * FROM " + 
                    ((dataSourceName == null)?"":(dataSourceName + "_"))+ 
                    "Path");

            while (rs.next()) {
                int pathId = rs.getInt(1);
                if (pathId > _maxId) {
                    _maxId = pathId;
                }
                _paths.put(rs.getString(2).toString().trim(), new Integer(pathId));
            }

            rs.close();
            stmt.close();
        } catch (Exception ex) {
            System.exit(0);
        }

    }
}
